export class ShaderTool {
    private input: HTMLInputElement;
    private shader: any;

    init(shader: any) {
        this.input = document.getElementById("input_id") as HTMLInputElement;
        this.input.onblur = this.onBlur.bind(this);
        this.input.onfocus = this.onFocus.bind(this);
        this.shader = shader;
    }

    onBlur(ev: FocusEvent) {
        debugger;
        if (this.shader) {
            this.shader.isFocus = false;
            this.shader.onBlur && this.shader.onBlur(this.input.value);
        }
    }
    onFocus(ev: FocusEvent) {
        debugger;
        if (this.shader) {
            this.shader.isFocus = true;
            this.shader.onFocus && this.shader.onFocus(this.input.value);
        }
    }

    

    static setProperty(text:string,caller:any){
        console.log("输入的数据:"+text);
        if(text){
            let arr = text.split("=");
            let key = arr[0].trim();
            let value = parseFloat(arr[1].trim());
            let keys = key.split(".");
            let target = caller;
            for (let index = 0; index < keys.length-1; index++) {
                const ikey = keys[index];
                target = target[ikey];
            }
            if(keys.length > 1){

                key = keys[keys.length-1];
            }
            target[key] = value;
        }
    }
}